package com.ptsolusi.ceriacrudwicket.logic;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ptsolusi.ceriacrudwicket.dao.CeriacrudwicketDao;
import com.ptsolusi.ceriacrudwicket.model.Customer;

public class CustomerLogicImpl implements CustomerLogic {
	
	private static Log log = LogFactory.getLog(CustomerLogicImpl.class);
	
	private CeriacrudwicketDao dao;
	
	public List<Customer> getAllCustomers() {
		return dao.getAllCustomer();
	}
	
	public List<Customer> getCustomerByFirstName(String firstName) {
		System.out.println("getCustomerByFirstName : "+firstName);
		if(firstName!=null)
			return dao.getCustomersByFirstName(firstName);
		return null;
	}
	
	public Customer getItemById(Long id) {
		log.debug("getItemById : "+id);
		return dao.findById(Customer.class, id);
	}
	
	public void deleteCustomer(Customer customer) {
		log.debug("deleteCustomer : "+customer);
		dao.delete(customer);
	}
	
	public void saveOrUpdateCustomer(Customer customer) {
		log.debug("saveOrUpdateCustomer : "+customer);
		dao.save(customer);
	}
	
	// ---injection goes here---
	public void setDao(CeriacrudwicketDao dao) {
		this.dao = dao;
	}
	
}
